package com.sfx.concurrent.demo.concurrent.AtomicTest.Account;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-19
 * Time: 19:22
 */
public class AccountUnSafe implements Account{

    private Integer balance;

    public AccountUnSafe(Integer balance) {
        this.balance = balance;
    }

    @Override
    public Integer getBalance() {
        synchronized (this) {
            return this.balance;
        }
    }

    @Override
    public  void withDraw(int account) {
        synchronized (this) {
            this.balance -= 10;
        }
    }

    public static void main(String[] args) {
        AccountUnSafe accountUnSafe = new AccountUnSafe(10000);
        Account.demo(accountUnSafe);
    }
}
